import { _decorator, Component, Node, input, Input, Sprite, Label } from 'cc';
const { ccclass, property } = _decorator;
import { xstory } from "./xstoryRun"
// @ts-ignore
import xstorydata from "./xstory_data.json"
@ccclass('xstoryExample')
export class xstoryExample extends Component {

    @property(Sprite)
    backgroundNode = null
    @property(Sprite)
    leftNode = null
    @property(Sprite)
    rightNode = null
    @property(Label)
    textNode = null

    myStory = null

    start() {

      this.myStory = new xstory({
        background:this.backgroundNode,
        left:this.leftNode,
        right:this.rightNode,
        text:this.textNode,
        data:xstorydata
      })

      input.on(Input.EventType.MOUSE_DOWN,this.mouseDown,this)
    }

    mouseDown(){
      if (this.myStory!=null) {
        let start = {
          sceneIndex:0,
          scriptindex:0
        }
        this.myStory.play(start,this.callback)
      }
    }
    callback(storyinfo:any){
      console.log("---当前播放")
      console.log(storyinfo.now)
      console.log("---下一个播放")
      console.log(storyinfo.next)
    }

    update(deltaTime: number) {
        
    }
}

